import java.util.Arrays;

public class Solution34 {
    public int[] searchRange(int[] nums, int target) {
        int left=0,right=nums.length-1;
        int ans1=-1;
        while (left<=right){
            int mid=(left+right)/2;
            if (nums[mid]>target){
                right=mid-1;
            }else if (nums[mid]<target){
                left=mid+1;
            }else{
                ans1=mid;
                right=mid-1;
            }
        }
        if (ans1==-1){
            return new int[]{-1,-1};
        }
        left=0;
        right=nums.length-1;
        int ans2=-1;
        while (left<=right){
            int mid=(left+right)/2;
            if (nums[mid]>target){
                right=mid-1;
            }else if (nums[mid]<target){
                left=mid+1;
            }else{
                ans2=mid;
                left=mid+1;
            }
        }
        return new int[]{ans1,ans2};
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Solution34().searchRange(new int[]{5,7,7,8,8,10},8)));
    }
}
